/*****************************************************
*
*               COPYRIGHT (c) 2015-2017 Hargic Corporation
*                         All Rights Reserved
*
* The source code contained or described herein and all documents
* related to the source code ("Material") are owned by Hargic
* Corporation or its licensors.  Title to the Material remains
* with Hargic Corporation or its suppliers and licensors.
*
* The Material is protected by worldwide copyright and trade secret
* laws and treaty provisions. No part of the Material may be used,
* copied, reproduced, modified, published, uploaded, posted, transmitted,
* distributed, or disclosed in any way except in accordance with the
* applicable license agreement.
*
* No license under any patent, copyright, trade secret or other
* intellectual property right is granted to or conferred upon you by
* disclosure or delivery of the Materials, either expressly, by
* implication, inducement, estoppel, except in accordance with the
* applicable license agreement.
*
* Unless otherwise agreed by Hargic in writing, you may not remove or
* alter this notice or any other notice embedded in Materials by Hargic
* or Hargic's suppliers or licensors in any way.
*
** Author: shengda.huang
** Date: 2018-05-26
*
*****************************************************/

#ifndef __AM23XX_H_
#define __AM23XX_H_

#ifdef __cplusplus
extern "C"{
#endif

/***** INCLUDES *************************************/

/***** DEFINES **************************************/

/*
 *  @brief: unit: us
 */
#define AM23XX_START_KEEP_LOW_TIME      1000
#define AM23XX_START_RELEASE_TIME       30
#define AM23XX_REPONSE_TIMEOUT			85
#define AM23XX_LOW_LEVEL_TIMEOUT		(55 + 35)
#define AM23XX_HIGH_LEVEL_TIMEOUT       (75 + 45)
#define AM23XX_RELEASE_TIMEOUT          (55 + 45)
/*
 *  @brief: 0: 50us low level + 22-30us high level
 *          1: 50us low level + 68-75us high level
 */
#define AM23XX_BIT_LEVEL_THRESHOLD      40

enum
{
	AM23XX_GPIO_DIR_INPUT,
	AM23XX_GPIO_DIR_OUTPUT,
};

enum
{
	AM23XX_GPIO_LEVEL_LOW,
	AM23XX_GPIO_LEVEL_HIGH,
};

/***** TYPEDEFS *************************************/

typedef struct
{
	void 		(*gpio_pullup)(void);
	void 		(*gpio_set_dir)(int dir);
	void 		(*gpio_set_output)(int level);
	int 		(*gpio_get_level)(void);
	void 		(*delay_us)(int us);
	// TEST PIN
	void 		(*test_pin_set)(int level);
} am23xx_func_t;

/***** CONSTANTS ************************************/

/***** VARIABLES ************************************/

/***** EXTERNAL VARIABLES ***************************/

/***** EXTERNAL FUNCTIONS ***************************/

/***** PROTOTYPES ***********************************/
void am23xx_register_gpio_func(am23xx_func_t *func);
int am23xx_start(void);
int am23xx_read_nbyte(unsigned char *byte, int btr);
int am23xx_release(void);


#ifdef __cplusplus
}
#endif

#endif /* __AM23XX_H_ */


